package com.xiyuan.smartutils.client.ws;

import com.xiyuan.smartutils.client.ws.client.WebSocketClient;
import com.xiyuan.smartutils.client.ws.client.WebSocketClientHandler;
import com.xiyuan.smartutils.client.ws.core.impl.rfc6455.DefaultWebsocket;
import com.xiyuan.smartutils.client.ws.core.proxy.Proxy;
import com.xiyuan.smartutils.client.exception.WebSocketException;

/**
 * WebSocket factory class.
 *
 * @author xiyuan
 */
public class WebSockets {
    
    /**
     * Create websocket
     *
     * @param url       the url
     * @param origin    the origin
     * @param handler   the handler
     * @param protocols the protocols
     * @return websocket
     * @throws WebSocketException the web socket exception
     */
    public static WebSocket create(String url,
                                   String origin,
                                   WebSocketClientHandler handler,
                                   String... protocols) throws WebSocketException {
        return new DefaultWebsocket(url, origin, handler, protocols);
    }
    
    /**
     * Create websocket
     *
     * @param url       the url
     * @param handler   the handler
     * @param protocols the protocols
     * @return websocket
     * @throws WebSocketException the web socket exception
     */
    public static WebSocketClient create(String url,
                                         WebSocketClientHandler handler,
                                         String... protocols) throws WebSocketException {
        return new DefaultWebsocket(url, handler, protocols);
    }
    
    /**
     * Create websocket
     *
     * @param url       the url
     * @param origin    the origin
     * @param proxy     the proxy
     * @param handler   the handler
     * @param protocols the protocols
     * @return the web socket
     * @throws WebSocketException the web socket exception
     */
    public static WebSocketClient create(String url,
                                         String origin,
                                         Proxy proxy,
                                         WebSocketClientHandler handler,
                                         String... protocols) throws WebSocketException {
        return new DefaultWebsocket(url, origin, proxy, handler, protocols);
    }
    
    /**
     * Create websocket
     *
     * @param url       the url
     * @param proxy     the proxy
     * @param handler   the handler
     * @param protocols the protocols
     * @return the web socket
     * @throws WebSocketException the web socket exception
     */
    public static WebSocketClient create(String url,
                                         Proxy proxy,
                                         WebSocketClientHandler handler,
                                         String... protocols) throws WebSocketException {
        return new DefaultWebsocket(url, proxy, handler, protocols);
    }
    
}
